package com.lingkang.top.seesister.activity.start;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;

import com.lingkang.top.seesister.R;
import com.lingkang.top.seesister.activity.home.HomeActivity;
import com.lingkang.top.seesister.utils.SharedPreferencesUtils;


public class StartFristWelcome extends Activity {

    private ProgressBar pbWelcomePage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_frist_welcome);
        //判断是否是首次启动app
        if ((boolean) SharedPreferencesUtils.get().get(this, "fristRunApp", false)) {
            startActivity(new Intent(StartFristWelcome.this, HomeActivity.class));
            //销毁当前页
            finish();
        } else {
            //初始化
            init();
        }
    }

    private void init() {
        SharedPreferencesUtils.get().put(this, "fristRunApp", true);
        pbWelcomePage = findViewById(R.id.pb_welcome_page);
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 10; i < 106; i = i + 3) {
                    try {
                        Thread.sleep(60);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    handler.sendEmptyMessage(i);
                }
            }
        }).start();
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what < 101) {
                pbWelcomePage.setProgress(msg.what);
            } else {
                startActivity(new Intent(StartFristWelcome.this, HomeActivity.class));
            }
        }
    };
}
